package se137.hrbust.hlgshopping137.utils;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * 无需通过Mapper及POJO，直接访问数据库的通用方法
 * @author Administrator
 *
 */
@Component
public class SQLCommService137 {
	@Resource(name = "jdbcTemplate") 
	public  JdbcTemplate jdbcTemplate;
	
	//返回指定SQL语句
	/**
	 * 返回指定SQL语句对应的查询结果
	 * @param sql
	 * @return
	 */
	public  String getFieldStr(String sql){
		String strResult="";
		try {
			Object object=jdbcTemplate.queryForObject(sql, String.class);
			if(object!=null)
				strResult=object+"";
			else
				strResult="";
			
		}catch(Exception ex) {
			strResult="";
		}
		return strResult;
		
	}
	
	public int updateSQL(String sql){

        return jdbcTemplate.update(sql);
	}
	public List<Map<String, Object>> listResult(String query){ 
		return jdbcTemplate.queryForList(query);
	}
}
